<template>
  <div class="login-page">
    <div class="back-home">
      <el-button 
        class="back-btn" 
        @click="$router.push('/main')"
        type="primary"
        round
      >
        <i class="el-icon-arrow-left"></i>
        返回首页
      </el-button>
    </div>
    
    <div class="content">
      <div class="container">
        <form>
          <div class="text-gradient">欢迎登录</div>
          <div class="inputBox">
            <el-input
              v-model="userForm.username"
              placeholder="用户名"
              style="width: 300px"
            />
          </div>
          <div class="inputBox">
            <el-input
              v-model="userForm.password"
              placeholder="密码"
              style="width: 300px"
            />
          </div>
          <div @click="login" class="btn">提交</div>
        </form>
      </div>
      
      <div class="beian">
        <a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备2023112859号-1</a>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";
import store from "@/store";
import { ElMessage } from "element-plus";
import adminsApi from "@/api/admins.js";

export default {
  data() {
    return {
      userForm: {
        username: localStorage.getItem('savedUsername') || '',
        password: localStorage.getItem('savedPassword') || ''
      },
      imgUrl: "/api/user/code?" + this.number,
      number: 0,
    };
  },
  created() {},
  methods: {
    login() {
      adminsApi.login(this.userForm).then((res) => {
        if (res.code == 200) {
          localStorage.setItem("token", res.data)
          localStorage.setItem('savedUsername', this.userForm.username)
          localStorage.setItem('savedPassword', this.userForm.password)
          this.$router.push("/backHome") // 使用路径来跳转
        } 
      });
    },
  },
};
</script>

<style scoped>
.login-page {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(40deg, #f96bab, #fcc785);
}

.content {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  width: 400px;
  min-height: 400px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
  box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

form {
  width: 100%;
  padding: 40px;
}

.text-gradient {
  width: 100%;
  text-align: center;
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 40px;
}

.inputBox {
  width: 100%;
  margin-top: 20px;
}

.btn {
  background: #fff;
  color: #666;
  cursor: pointer;
  margin-top: 20px;
  padding: 10px 0;
  border-radius: 4px;
  font-weight: 600;
  width: 300px;
  text-align: center;
  transition: all 0.3s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.9);
  transform: translateY(-2px);
}

.beian {
  position: fixed;
  bottom: 20px;
  width: 100%;
  text-align: center;
}

.beian a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 14px;
}

.beian a:hover {
  color: #fff;
}

:deep(.el-input__inner) {
  background: rgba(255, 255, 255, 0.8);
  border: none;
  outline: none;
  padding: 10px 20px;
  border-radius: 35px;
  color: #333;
  font-size: 16px;
  font-weight: 500;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

:deep(.el-input__inner)::placeholder {
  color: #666;
  opacity: 0.8;
}

:deep(.el-input__inner):focus {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.back-home {
  position: fixed;
  top: 30px;
  left: 40px;
  z-index: 100;
}

.back-btn {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: #666;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.back-btn:hover {
  transform: translateX(-5px);
  background: rgba(255, 255, 255, 1);
  color: #333;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.back-btn i {
  font-size: 18px;
  transition: all 0.3s ease;
}

.back-btn:hover i {
  transform: translateX(-3px);
}

/* 适配移动端 */
@media screen and (max-width: 768px) {
  .back-home {
    top: 20px;
    left: 20px;
  }
  
  .back-btn {
    padding: 10px 20px;
    font-size: 14px;
  }
}
</style>
